/* 公用方法 */
import config from "@/app.config.js";
import $api from "@/common/js/api.js";
import $util from "@/common/js/util.js";
import resource from "@/common/js/resource.js";

import Dict from "@/domain/base/Dict.js"

import dbNav from "@/data/dbNav.js"
import dbDict from "@/data/dbDict.js"


let $GLOBAL;

export default {
	// 初始化数据
	initData(globalData) {
		if (config.debug) console.log('==== global.js 初始化公共数据 in ====')
		$GLOBAL = globalData;
		this.getSite();
		this.getNavList();
		// this.getAllDict();
		// this.getDictList2();
	},
	getSite() {
		if ($GLOBAL.site && $GLOBAL.site._id) return;
		// vk.callFunction({
		// 	url: 'client/lzy_common/pub.app.getInfo'
		// }).then((res) => {
		// 	console.log('网站信息', res)
		// 	$GLOBAL.site = res.item;
		// 	resource.logo = res.item.img1 && res.item.img1[0];
		// 	resource.topUrl = res.item.img2 && res.item.img2[0];
		// 	resource.bgUrl = res.item.img3[0];
		// 	uni.$emit('site-init')
		// });
		
		// resource.bgUrl = "https://mp-adf91af7-51bf-4e2e-abae-1ed51120ab92.cdn.bspapp.com/cloudstorage/9d7a2ba6-71fb-4312-8412-6f48c435b4f6.jpg"
		resource.bgUrl = "https://mp-adf91af7-51bf-4e2e-abae-1ed51120ab92.cdn.bspapp.com/cloudstorage/1ca495b6-1d7c-454b-adf8-47c112d6e6a3.jpg"
		resource.loginTop = "https://mp-adf91af7-51bf-4e2e-abae-1ed51120ab92.cdn.bspapp.com/cloudstorage/c22ed449-a9f0-4de0-9ab4-ef0ea8dd2216.png"
		uni.$emit('site-init')
	},
	// 获取导航列表
	getNavList() {
		// if ($GLOBAL.navList && $GLOBAL.navList.length > 0) return;
		// vk.callFunction({
		// 	url: 'client/lzy_common/pub.nav.getList',
		// 	title: '请求中...',
		// 	data: {
		// 		// is_index: true
		// 	},
		// }).then(res => {
		// 	console.log('导航列表', res)
		// 	console.log('导航列表', JSON.stringify(res.rows))
		// 	// $GLOBAL.navList = res.rows.filter(item => item.is_index);
		// 	$GLOBAL.navList = res.rows;
		// 	uni.$emit('nav-init')
		// });
		
		$GLOBAL.navList = dbNav;
		uni.$emit('nav-init')
	},
	// 全部字典项
	getAllDict() {
		// if ($GLOBAL.dictList && $GLOBAL.dictList.length > 0) return;
		// vk.callFunction({
		// 	url: 'client/lzy_common/pub.dic.getAll'
		// }).then(res => {
		// 	console.log('全部字典项', res)
		// 	console.log('全部字典项', JSON.stringify(res.rows))
		// 	$GLOBAL.dictList = res.rows;
		// 	uni.$emit('dict-init')
		// });
		
		// $GLOBAL.dictList = dbDict;
		// uni.$emit('dict-init')
	},
	// .net字典项
	getDictList2() {
		$util.request($api.GetCategoryOptions)
		.then(res => {
			if(config.debug) console.log('产品类别', res)
			$GLOBAL.categoryOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetUnitOptions)
		.then(res => {
			if(config.debug) console.log('计量单位', res)
			$GLOBAL.unitOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetStorageOptions)
		.then(res => {
			if(config.debug) console.log('保存条件', res)
			$GLOBAL.storageOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetMealsOptions)
		.then(res => {
			if(config.debug) console.log('餐次', res)
			$GLOBAL.mealsOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetWasteTypeOptions)
		.then(res => {
			if(config.debug) console.log('废旧物分类', res)
			$GLOBAL.wasteOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetTablewareTypeOptions)
		.then(res => {
			if(config.debug) console.log('餐具类型', res)
			$GLOBAL.tablewareOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetXiuJiaZhuangTaiOptions)
		.then(res => {
			if(config.debug) console.log('休假状态', res)
			$GLOBAL.xiujiaOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetChuQinZhuangTaiOptions)
		.then(res => {
			if(config.debug) console.log('出勤情况', res)
			$GLOBAL.chuqinOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetChenJianQingKuangOptions)
		.then(res => {
			if(config.debug) console.log('晨检情况', res)
			$GLOBAL.chenjianOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetSexOptions)
		.then(res => {
			if(config.debug) console.log('性别', res)
			$GLOBAL.sexOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetDutyOptions)
		.then(res => {
			if(config.debug) console.log('职务结果', res)
			$GLOBAL.dutyOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetJobStatusOptions)
		.then(res => {
			if(config.debug) console.log('在职状态', res)
			$GLOBAL.jobStatusOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetInspectItemOptions)
		.then(res => {
			if(config.debug) console.log('检测项目', res)
			$GLOBAL.inspectItemOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetDayAnswerOptionsOptions)
		.then(res => {
			if(config.debug) console.log('日管控勾选的选项', res)
			$GLOBAL.dayAnswerOptionsOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetWeekWorkResultOptions)
		.then(res => {
			if(config.debug) console.log('周排查工作结果', res)
			$GLOBAL.weekWorkResultOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetSupplierTypeOptions)
		.then(res => {
			if(config.debug) console.log('供应商类别', res)
			$GLOBAL.supplierTypeOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetSiteOptions)
		.then(res => {
			if(config.debug) console.log('消杀场所', res)
			$GLOBAL.siteOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetEquipmentOptions)
		.then(res => {
			if(config.debug) console.log('消杀设备', res)
			$GLOBAL.equipmentOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetXiujiaOptions)
		.then(res => {
			if(config.debug) console.log('休假状态', res)
			$GLOBAL.xiujiaOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetChuqinOptions)
		.then(res => {
			if(config.debug) console.log('出勤情况', res)
			$GLOBAL.chuqinOptions = Dict.newFormList(res.rows);
		})
		$util.request($api.GetChenjianOptions)
		.then(res => {
			if(config.debug) console.log('晨检情况', res)
			$GLOBAL.chenjianOptions = Dict.newFormList(res.rows);
		})
	},
	// .net字典项
	getDictListByUser(qiyeID) {
		// $util.request($api.GetDutyList, {qiyeID})
		// .then(res => {
		// 	if(config.debug) console.log('职务（按企业）', res)
		// 	$GLOBAL.dutyList = res.rows.map(data => {
		// 		return {
		// 			dict_value: data.ZhiWuID,
		// 			dict_label: data.ZhiWuMingCheng
		// 		}
		// 	})
		// })
	},
}